import {IS_DEBUG} from '@/env'
export default {
	doRequest(method, url, data, contentType,type = true) {
		if(IS_DEBUG){
			var apiurl="https://teststate.renruikeji.cn/api/userservice/tags";
		}else{
			// var apiurl="https://state.renkangshangcheng.cn/api/userservice/tags";
			var apiurl="https://state.renruikeji.cn/api/userservice/tags";
		}
		var token = uni.getStorageSync('token');
		if (type) {
			uni.showLoading({
				title: "加载中"
			})
		}
		return new Promise((resolve, reject) => {
			let header = {}
			if(contentType === 'json'){
				header = {
				    'content-type': 'application/json',
					'Authorization':token,
				}
			}else{
				header = {
				    'content-type': 'application/x-www-form-urlencoded',
					'Authorization':token,
				}
			}
			uni.request({
				method: method,
				url: apiurl + url,
				data: data,
				header: header,
				success: function(result) {
					uni.hideLoading();
					if (result.data.code == 401) {
						uni.removeStorageSync('token')
					}
					if (result.data.code == 400) {
						if (token) {
							uni.showToast({
								title: result.data.msg,
								icon: 'none'
							})
						}
					}
					resolve(result)
				},
				fail: function(e) {
					reject(e)
				},
			})
		})

	},

}
